package com.mera.tektronix.csviewer.transformers;

import com.mera.tektronix.csviewer.common.dto.ProjectDto
import com.mera.tektronix.csviewer.domain.*

public class ProjectTransformer extends AbstractTransformer<ProjectDto, Project> {

	@Override
	protected Project getDomainInstance(ProjectDto dto) {
		if(dto.id != null) {
			return Project.get(dto.id);
		}
		return new Project();
	}

	@Override
	protected ProjectDto getDtoInstance(Project domain) {
		return new ProjectDto();
	}

	@Override
	protected void transformDtoToDomainInternal(ProjectDto dto, Project domain) {		
		domain.name = dto.name;
		domain.email = dto.email;
		domain.phone = dto.phone;
		domain.department = Department.get(dto.departmentId);
	}

	@Override
	protected void transformDomainToDtoInternal(Project domain, ProjectDto dto) {		
		dto.id = domain.id;
		dto.name = domain.name;
		dto.email = domain.email;
		dto.phone = domain.phone;
		dto.departmentId = domain.department.id;
		dto.departmentName = domain.department.name;
	}

}
